﻿Type.registerNamespace("DNNDev.DNNModules.NewsBeast");

DNNDev.DNNModules.NewsBeast.ServiceClient = function (moduleId) {
    var self = this;
    var serviceFramework = $.ServicesFramework(moduleId);
    var serviceRoot = serviceFramework.getServiceRoot('NewsBeast') + 'Service/';


    self.getAllNewsletters = function () {
        console.log("Get Model from Service");
        return $.ajax({
            type: "GET",
            url: serviceRoot + "GetAllNewsletters",
            beforeSend: serviceFramework.setModuleHeaders,
            cache: false
        });
    };

    self.deleteNewsletter = function (item) {
        console.log("Delete newsletter with Service");
        return $.ajax({
            type: "POST",
            url: serviceRoot + "DeleteNewsletter",
            beforeSend: serviceFramework.setModuleHeaders,
            data: item,
            cache: false
        });
    };

    self.insertNewsletter = function (item) {
        console.log("Insert Newsletter with Service");
        return $.ajax({
            type: "POST",
            url: serviceRoot + "InsertNewsletter",
            beforeSend: serviceFramework.setModuleHeaders,
            data: item,
            cache: false
        });
    };

    self.updateNewsletter = function (item) {
        console.log("Update Newsletter with Service");
        return $.ajax({
            type: "POST",
            url: serviceRoot + "UpdateNewsletter",
            beforeSend: serviceFramework.setModuleHeaders,
            data: item,
            cache: false
        });
    };

    self.getAllItems = function (moduleId) {
        console.log("Get Model from Service");
        return $.ajax({
            type: "GET",
            url: serviceRoot + "GetAllItems",
            beforeSend: serviceFramework.setModuleHeaders,
            data: "moduleid="+ moduleId,
            cache: false
        });
    };

    self.insertItem = function (item) {
        console.log("Insert Item with Service");
        return $.ajax({
            type: "POST",
            url: serviceRoot + "InsertItem",
            beforeSend: serviceFramework.setModuleHeaders,
            data: item,
            cache: false
        });
    };
    
    self.updateItem = function (item) {
        console.log("Update Item with Service");
        return $.ajax({
            type: "POST",
            url: serviceRoot + "UpdateItem",
            beforeSend: serviceFramework.setModuleHeaders,
            data: item,
            cache: false
        });
    };
    
    self.deleteItem = function (item) {
        console.log("Delete Item with Service");
        return $.ajax({
            type: "POST",
            url: serviceRoot + "DeleteItem",
            beforeSend: serviceFramework.setModuleHeaders,
            data: item,
            cache: false
        });
    };
};
